package com.ts.modules.movie_session.service.impl;

import com.alibaba.fastjson.JSON;
import com.ts.common.entity.ResponseResult;
import com.ts.common.page.PageData;
import com.ts.feign.api.SessionServices;

import com.ts.feign.dto.SessionDTO;
import com.ts.modules.movie_session.service.SessionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Map;

/**
 * 
 *
 * @author Ywl 193363874@qq.com
 * @since 1.0.0 2023-07-15
 */
@Service
@Slf4j
public class SessionServiceImpl implements SessionService {
   @Autowired
    SessionServices sessionServices;

    @Override
    public PageData<SessionDTO> page(Map<String, Object> params) {
        ResponseResult page=sessionServices.page(params);
        return exchange(page.get("data"),PageData.class);
    }

    @Override
    public SessionDTO get(Long id) {
        ResponseResult responseResult=sessionServices.get(id);

        return exchange(responseResult.get("data"), SessionDTO.class);
    }

    @Override
    public void save(SessionDTO dto) {
        sessionServices.save(dto);
    }
    public <T>  T  exchange(Object object,Class<T> objclass){
        String jsonString=JSON.toJSONString(object);
        return JSON.parseObject(jsonString, objclass);
    }
}